<?php

include _ITSTOCK_INCLUDE_DIR_.'html_options.inc.php';

itstock_structure($structure, 'version');
$edit = false;

if(isset($_POST['id'])){
    $structure['where'][0] = sprintf("`%s`.`id`='%s'", $structure['table'], itstock_decode($_POST['id']));
    $edit = itstock_search_all($structure);
}

?><b><?php echo (!$edit?'New ':'')?>Product Version</b>
  <br><br><br>
<form class="save" action="store.php?type=version" method="POST" id="form_version" autocomplete="off">
  <input type="hidden" value="<?php echo ($edit?itstock_encode($structure['data'][0]['id']):'')?>" id="id" name="id">
  <table>
    <tr>
      <td><label>Vendor:</label></td>
      <td><select id="vendor_id" required autofocus onchange="itstock_request_options('product_id', 'product', 'product', 'vendor_id');"><?php
        itstock_html_options('vendor', 'vendor', 'vendor_id', $structure, $edit);
      ?></select>
      </td>
    </tr>
    <tr>
      <td><label>Product:</label></td>
      <td><select name="product_id" id="product_id" required><?php
       if($edit) {
          itstock_structure($products, 'product');
          $products['where'][0] = 'vendor_id='.$structure['data'][0]['vendor_id'];
          itstock_html_options(null, 'product', 'product_id',  $structure, $edit, $products);
        } else {
          echo '<option value="">Please select a Vendor</option>';
        }
      ?></select>
      </td>
    </tr>
    <tr>
      <td><label>Version:</label></td>
      <td><input type="text" autofocus name="version" style="width: 200px" value="<?php echo ($edit?$structure['data'][0]['version']:'')?>" required placeholder="Version"></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><br><input type="submit" value="Save" style="margin-right: 100px;"><input type="reset" value="Reset"></td>
    </tr>
  </table>
</form>
